package cn.aresoft.framework.plugins.pagination.ibatis;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import cn.aresoft.framework.support.dao.IDaoSupport;


/**
 *  <p>Title: IbatisPageServiceImpl</p>
 *  <p>Description: IbatisPageService</p>
 *  <p>Copyright: Copyright (c) 2010-6-18</p>
 *  <p>Company: 蓝色天空工作室 </p>
 *
 * @author ShiGuanghui
 */
@Component
public class IbatisPageServiceImpl implements IbatisPageService {
	
	private static final long serialVersionUID = 1L;
	private static final Logger logger = Logger.getLogger(IbatisPageServiceImpl.class);
	
	private IDaoSupport iDaoSupport;

	public void setIDaoSupport(IDaoSupport iDaoSupport) {
		this.iDaoSupport = iDaoSupport;
	}


	public List findForSubList(String sqlName, Serializable arg,
			IbatisPage pageBean) {
		
		List rs_list = null;
		
		if (pageBean != null) {
			
			//当记录大于0的时候，查询出分页列表
			if (pageBean.getCount() > 0) {
				logger.debug("正在进行分页查询：总记录数[" + pageBean.getCount()
						+ "],总页数[" + pageBean.getPageCount() + "],当前页面["
						+ pageBean.getPage() + "],页面记录数["
						+ pageBean.getPageSize() + "],起始记录数["
						+ pageBean.getBegin() + "],结束记录数["
						+ pageBean.getOffset() + "]");
				
				rs_list = iDaoSupport.findForSubList(sqlName,
						arg, pageBean.getBegin(), pageBean.getOffset());
			}
		} else {
			rs_list = iDaoSupport.findForList(sqlName, arg);
		}
		return rs_list;
	}

	
	public int tableCountNum(String sqlName, Serializable obj) {
		return iDaoSupport.tableCountNum(sqlName, obj);
	}
	
}
